angular.module('app')
  .directive('adminAuth', ['$rootScope', function ($rootScope) {
    return {
      restrict: 'A',
      scope: {
        'auth': '=adminAuth'
      },
      link: function ($scope, iElement, iAttrs) {
        if (!$scope.auth) return;

        var auths = $scope.auth.split('||');
        var flag = false;

        if (!window.__AUTH__) return;

        angular.forEach(auths, function(i){
          if (window.__AUTH__.node.hasOwnProperty(i)) {
            flag = true;
          }
        });
        angular.forEach(auths, function(i){
          angular.forEach(window.__AUTH__.node, function(item, key){
            for(var j in item){
              if (key+'.'+item[j] == i){
                flag = true;
              }
            }
          });
        });

        if (flag){
          return;
        }

        $(iElement).hide();
      }
    };
  }])